home *** CD-ROM | disk | FTP | other *** search
/ Apple Developer Connection Student Program / ADC Tools Sampler CD Disk 3 1999.iso / Metrowerks CodeWarrior / Java Support / Java_Source / Java2 / src / java / awt / Toolkit.java < prev    next >
Encoding:
Java Source  |  1999-05-28  |  52.8 KB  |  1,452 lines  |  [TEXT/CWIE]

  1. /*
  2.  * @(#)Toolkit.java    1.123 98/10/07
  3.  *
  4.  * Copyright 1995-1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  *
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14.  
  15. package java.awt;
  16.  
  17. import java.util.MissingResourceException;
  18. import java.util.Properties;
  19. import java.util.ResourceBundle;
  20. import java.util.StringTokenizer;
  21. import java.awt.event.*;
  22. import java.awt.peer.*;
  23. import java.awt.image.ImageObserver;
  24. import java.awt.image.ImageProducer;
  25. import java.awt.image.ColorModel;
  26. import java.awt.datatransfer.Clipboard;
  27. import java.awt.dnd.DnDConstants;
  28. import java.awt.dnd.DragSource;
  29. import java.awt.dnd.DragGestureRecognizer;
  30. import java.awt.dnd.DragGestureEvent;
  31. import java.awt.dnd.DragGestureListener;
  32. import java.awt.dnd.InvalidDnDOperationException;
  33. import java.awt.dnd.peer.DragSourceContextPeer;
  34. import java.net.URL;
  35. import java.io.BufferedInputStream;
  36. import java.io.File;
  37. import java.io.FileInputStream;
  38. import java.security.AccessController;
  39. import java.security.PrivilegedAction;
  40.  
  41.  
  42. import java.util.EventListener;
  43. import java.util.Map;
  44. import java.util.HashMap;
  45. import java.util.WeakHashMap;
  46.  
  47. import java.beans.PropertyChangeListener;
  48. import java.beans.PropertyChangeSupport;
  49.  
  50. /**
  51.  * This class is the abstract superclass of all actual
  52.  * implementations of the Abstract Window Toolkit. Subclasses of
  53.  * <code>Toolkit</code> are used to bind the various components
  54.  * to particular native toolkit implementations.
  55.  * <p>
  56.  * Most applications should not call any of the methods in this
  57.  * class directly. The methods defined by <code>Toolkit</code> are
  58.  * the "glue" that joins the platform-independent classes in the
  59.  * <code>java.awt</code> package with their counterparts in
  60.  * <code>java.awt.peer</code>. Some methods defined by
  61.  * <code>Toolkit</code> query the native operating system directly.
  62.  *
  63.  * @version     1.123, 10/07/98
  64.  * @author    Sami Shaio
  65.  * @author    Arthur van Hoff
  66.  
  67.  * @author    Fred Ecks
  68.  * @since       JDK1.0
  69.  */
  70. public abstract class  Toolkit {
  71.  
  72.     /**
  73.      * Creates this toolkit's implementation of <code>Button</code> using
  74.      * the specified peer interface.
  75.      * @param     target the button to be implemented.
  76.      * @return    this toolkit's implementation of <code>Button</code>.
  77.      * @see       java.awt.Button
  78.      * @see       java.awt.peer.ButtonPeer
  79.      */
  80.     protected abstract ButtonPeer     createButton(Button target);
  81.  
  82.     /**
  83.      * Creates this toolkit's implementation of <code>TextField</code> using
  84.      * the specified peer interface.
  85.      * @param     target the text field to be implemented.
  86.      * @return    this toolkit's implementation of <code>TextField</code>.
  87.      * @see       java.awt.TextField
  88.      * @see       java.awt.peer.TextFieldPeer
  89.      */
  90.     protected abstract TextFieldPeer     createTextField(TextField target);
  91.  
  92.     /**
  93.      * Creates this toolkit's implementation of <code>Label</code> using
  94.      * the specified peer interface.
  95.      * @param     target the label to be implemented.
  96.      * @return    this toolkit's implementation of <code>Label</code>.
  97.      * @see       java.awt.Label
  98.      * @see       java.awt.peer.LabelPeer
  99.      */
  100.     protected abstract LabelPeer     createLabel(Label target);
  101.  
  102.     /**
  103.      * Creates this toolkit's implementation of <code>List</code> using
  104.      * the specified peer interface.
  105.      * @param     target the list to be implemented.
  106.      * @return    this toolkit's implementation of <code>List</code>.
  107.      * @see       java.awt.List
  108.      * @see       java.awt.peer.ListPeer
  109.      */
  110.     protected abstract ListPeer     createList(List target);
  111.  
  112.     /**
  113.      * Creates this toolkit's implementation of <code>Checkbox</code> using
  114.      * the specified peer interface.
  115.      * @param     target the check box to be implemented.
  116.      * @return    this toolkit's implementation of <code>Checkbox</code>.
  117.      * @see       java.awt.Checkbox
  118.      * @see       java.awt.peer.CheckboxPeer
  119.      */
  120.     protected abstract CheckboxPeer     createCheckbox(Checkbox target);
  121.  
  122.     /**
  123.      * Creates this toolkit's implementation of <code>Scrollbar</code> using
  124.      * the specified peer interface.
  125.      * @param     target the scroll bar to be implemented.
  126.      * @return    this toolkit's implementation of <code>Scrollbar</code>.
  127.      * @see       java.awt.Scrollbar
  128.      * @see       java.awt.peer.ScrollbarPeer
  129.      */
  130.     protected abstract ScrollbarPeer     createScrollbar(Scrollbar target);
  131.  
  132.     /**
  133.      * Creates this toolkit's implementation of <code>ScrollPane</code> using
  134.      * the specified peer interface.
  135.      * @param     target the scroll pane to be implemented.
  136.      * @return    this toolkit's implementation of <code>ScrollPane</code>.
  137.      * @see       java.awt.ScrollPane
  138.      * @see       java.awt.peer.ScrollPanePeer
  139.      * @since     JDK1.1
  140.      */
  141.     protected abstract ScrollPanePeer     createScrollPane(ScrollPane target);
  142.  
  143.     /**
  144.      * Creates this toolkit's implementation of <code>TextArea</code> using
  145.      * the specified peer interface.
  146.      * @param     target the text area to be implemented.
  147.      * @return    this toolkit's implementation of <code>TextArea</code>.
  148.      * @see       java.awt.TextArea
  149.      * @see       java.awt.peer.TextAreaPeer
  150.      */
  151.     protected abstract TextAreaPeer      createTextArea(TextArea target);
  152.  
  153.     /**
  154.      * Creates this toolkit's implementation of <code>Choice</code> using
  155.      * the specified peer interface.
  156.      * @param     target the choice to be implemented.
  157.      * @return    this toolkit's implementation of <code>Choice</code>.
  158.      * @see       java.awt.Choice
  159.      * @see       java.awt.peer.ChoicePeer
  160.      */
  161.     protected abstract ChoicePeer    createChoice(Choice target);
  162.  
  163.     /**
  164.      * Creates this toolkit's implementation of <code>Frame</code> using
  165.      * the specified peer interface.
  166.      * @param     target the frame to be implemented.
  167.      * @return    this toolkit's implementation of <code>Frame</code>.
  168.      * @see       java.awt.Frame
  169.      * @see       java.awt.peer.FramePeer
  170.      */
  171.     protected abstract FramePeer      createFrame(Frame target);
  172.  
  173.     /**
  174.      * Creates this toolkit's implementation of <code>Canvas</code> using
  175.      * the specified peer interface.
  176.      * @param     target the canvas to be implemented.
  177.      * @return    this toolkit's implementation of <code>Canvas</code>.
  178.      * @see       java.awt.Canvas
  179.      * @see       java.awt.peer.CanvasPeer
  180.      */
  181.     protected abstract CanvasPeer     createCanvas(Canvas target);
  182.  
  183.     /**
  184.      * Creates this toolkit's implementation of <code>Panel</code> using
  185.      * the specified peer interface.
  186.      * @param     target the panel to be implemented.
  187.      * @return    this toolkit's implementation of <code>Panel</code>.
  188.      * @see       java.awt.Panel
  189.      * @see       java.awt.peer.PanelPeer
  190.      */
  191.     protected abstract PanelPeer      createPanel(Panel target);
  192.  
  193.     /**
  194.      * Creates this toolkit's implementation of <code>Window</code> using
  195.      * the specified peer interface.
  196.      * @param     target the window to be implemented.
  197.      * @return    this toolkit's implementation of <code>Window</code>.
  198.      * @see       java.awt.Window
  199.      * @see       java.awt.peer.WindowPeer
  200.      */
  201.     protected abstract WindowPeer      createWindow(Window target);
  202.  
  203.     /**
  204.      * Creates this toolkit's implementation of <code>Dialog</code> using
  205.      * the specified peer interface.
  206.      * @param     target the dialog to be implemented.
  207.      * @return    this toolkit's implementation of <code>Dialog</code>.
  208.      * @see       java.awt.Dialog
  209.      * @see       java.awt.peer.DialogPeer
  210.      */
  211.     protected abstract DialogPeer      createDialog(Dialog target);
  212.  
  213.     /**
  214.      * Creates this toolkit's implementation of <code>MenuBar</code> using
  215.      * the specified peer interface.
  216.      * @param     target the menu bar to be implemented.
  217.      * @return    this toolkit's implementation of <code>MenuBar</code>.
  218.      * @see       java.awt.MenuBar
  219.      * @see       java.awt.peer.MenuBarPeer
  220.      */
  221.     protected abstract MenuBarPeer      createMenuBar(MenuBar target);
  222.  
  223.     /**
  224.      * Creates this toolkit's implementation of <code>Menu</code> using
  225.      * the specified peer interface.
  226.      * @param     target the menu to be implemented.
  227.      * @return    this toolkit's implementation of <code>Menu</code>.
  228.      * @see       java.awt.Menu
  229.      * @see       java.awt.peer.MenuPeer
  230.      */
  231.     protected abstract MenuPeer      createMenu(Menu target);
  232.  
  233.     /**
  234.      * Creates this toolkit's implementation of <code>PopupMenu</code> using
  235.      * the specified peer interface.
  236.      * @param     target the popup menu to be implemented.
  237.      * @return    this toolkit's implementation of <code>PopupMenu</code>.
  238.      * @see       java.awt.PopupMenu
  239.      * @see       java.awt.peer.PopupMenuPeer
  240.      * @since     JDK1.1
  241.      */
  242.     protected abstract PopupMenuPeer    createPopupMenu(PopupMenu target);
  243.  
  244.     /**
  245.      * Creates this toolkit's implementation of <code>MenuItem</code> using
  246.      * the specified peer interface.
  247.      * @param     target the menu item to be implemented.
  248.      * @return    this toolkit's implementation of <code>MenuItem</code>.
  249.      * @see       java.awt.MenuItem
  250.      * @see       java.awt.peer.MenuItemPeer
  251.      */
  252.     protected abstract MenuItemPeer      createMenuItem(MenuItem target);
  253.  
  254.     /**
  255.      * Creates this toolkit's implementation of <code>FileDialog</code> using
  256.      * the specified peer interface.
  257.      * @param     target the file dialog to be implemented.
  258.      * @return    this toolkit's implementation of <code>FileDialog</code>.
  259.      * @see       java.awt.FileDialog
  260.      * @see       java.awt.peer.FileDialogPeer
  261.      */
  262.     protected abstract FileDialogPeer    createFileDialog(FileDialog target);
  263.  
  264.     /**
  265.      * Creates this toolkit's implementation of <code>CheckboxMenuItem</code> using
  266.      * the specified peer interface.
  267.      * @param     target the checkbox menu item to be implemented.
  268.      * @return    this toolkit's implementation of <code>CheckboxMenuItem</code>.
  269.      * @see       java.awt.CheckboxMenuItem
  270.      * @see       java.awt.peer.CheckboxMenuItemPeer
  271.      */
  272.     protected abstract CheckboxMenuItemPeer    createCheckboxMenuItem(CheckboxMenuItem target);
  273.  
  274.     private static java.awt.LightweightPeer lightweightMarker;
  275.  
  276.     /**
  277.      * Creates a peer for a component or container.  This peer is windowless
  278.      * and allows the Component and Container classes to be extended directly
  279.      * to create windowless components that are defined entirely in java.
  280.      *
  281.      * @param target The Component to be created.
  282.      */
  283.     protected java.awt.peer.LightweightPeer createComponent(Component target) {
  284.         if (lightweightMarker == null) {
  285.             lightweightMarker = new java.awt.LightweightPeer(target);
  286.         }
  287.     return lightweightMarker;
  288.     }
  289.  
  290.     /**
  291.      * Creates this toolkit's implementation of <code>Font</code> using
  292.      * the specified peer interface.
  293.      * @param     target the font to be implemented.
  294.      * @return    this toolkit's implementation of <code>Font</code>.
  295.      * @see       java.awt.Font
  296.      * @see       java.awt.peer.FontPeer
  297.      * @see       java.awt.GraphicsEnvironment#getAllFonts
  298.      * @deprecated  see java.awt.GraphicsEnvironment#getAllFonts
  299.      */
  300.     protected abstract FontPeer getFontPeer(String name, int style);
  301.  
  302.     /**
  303.      * Fills in the integer array that is supplied as an argument
  304.      * with the current system color values.
  305.      * <p>
  306.      * This method is called by the method <code>updateSystemColors</code>
  307.      * in the <code>SystemColor</code> class.
  308.      * @param     an integer array.
  309.      * @see       java.awt.SystemColor#updateSystemColors
  310.      * @since     JDK1.1
  311.      */
  312.     protected void loadSystemColors(int[] systemColors) {
  313.     }
  314.  
  315.     /**
  316.      * Gets the size of the screen.
  317.      * @return    the size of this toolkit's screen, in pixels.
  318.      */
  319.     public abstract Dimension getScreenSize();
  320.  
  321.     /**
  322.      * Returns the screen resolution in dots-per-inch.
  323.      * @return    this toolkit's screen resolution, in dots-per-inch.
  324.      */
  325.     public abstract int getScreenResolution();
  326.  
  327.     /**
  328.      * Determines the color model of this toolkit's screen.
  329.      * <p>
  330.      * <code>ColorModel</code> is an abstract class that
  331.      * encapsulates the ability to translate between the
  332.      * pixel values of an image and its red, green, blue,
  333.      * and alpha components.
  334.      * <p>
  335.      * This toolkit method is called by the
  336.      * <code>getColorModel</code> method
  337.      * of the <code>Component</code> class.
  338.      * @return    the color model of this toolkit's screen.
  339.      * @see       java.awt.image.ColorModel
  340.      * @see       java.awt.Component#getColorModel
  341.      */
  342.     public abstract ColorModel getColorModel();
  343.  
  344.     /**
  345.      * Returns the names of the available fonts in this toolkit.<p>
  346.      * For 1.1, the following font names are deprecated (the replacement
  347.      * name follows):
  348.      * <ul>
  349.      * <li>TimesRoman (use Serif)
  350.      * <li>Helvetica (use SansSerif)
  351.      * <li>Courier (use Monospaced)
  352.      * </ul><p>
  353.      * The ZapfDingbats fontname is also deprecated in 1.1 but the characters
  354.      * are defined in Unicode starting at 0x2700, and as of 1.1 Java supports
  355.      * those characters.
  356.      * @return    the names of the available fonts in this toolkit.
  357.      * @deprecated see {@link java.awt.GraphicsEnvironment#getAvailableFontFamilyNames()}
  358.      * @see java.awt.GraphicsEnvironment#getAvailableFontFamilyNames()
  359.      */
  360.     public abstract String[] getFontList();
  361.  
  362.     /**
  363.      * Gets the screen device metrics for rendering of the font.
  364.      * @param     font   a font.
  365.      * @return    the screen metrics of the specified font in this toolkit.
  366.      * @deprecated  This returns integer metrics for the default screen.
  367.      * @see java.awt.Font#LineMetrics
  368.      * @see java.awt.Font#retreiveLineMetrics
  369.      * @see java.awt.GraphicsEnvironment#getScreenDevices;
  370.      */
  371.     public abstract FontMetrics getFontMetrics(Font font);
  372.  
  373.     /**
  374.      * Synchronizes this toolkit's graphics state. Some window systems
  375.      * may do buffering of graphics events.
  376.      * <p>
  377.      * This method ensures that the display is up-to-date. It is useful
  378.      * for animation.
  379.      */
  380.     public abstract void sync();
  381.  
  382.     /**
  383.      * The default toolkit.
  384.      */
  385.     private static Toolkit toolkit;
  386.  
  387.     /**
  388.      * Loads additional classes into the VM, using the property
  389.      * 'assistive_technologies' specified in the Sun reference
  390.      * implementation by a line in the 'accessibility.properties'
  391.      * file.  The form is "assistive_technologies=..." where
  392.      * the "..." is a comma-separated list of assistive technology
  393.      * classes to load.  Each class is loaded in the order given
  394.      * and a single instance of each is created using
  395.      * Class.forName(class).newInstance().  All errors are handled
  396.      * via an AWTError exception.
  397.      *
  398.      * <p>The assumption is made that assistive technology classes are supplied
  399.      * as part of INSTALLED (as opposed to: BUNDLED) extensions or specified
  400.      * on the class path
  401.      * (and therefore can be loaded using the class loader returned by
  402.      * a call to <code>ClassLoader.getSystemClassLoader</code>, whose
  403.      * delegation parent is the extension class loader for installed
  404.      * extensions).
  405.      */
  406.     private static void loadAssistiveTechnologies() {
  407.         final String sep = File.separator;
  408.         final Properties properties = new Properties();
  409.  
  410.     java.security.AccessController.doPrivileged(
  411.         new java.security.PrivilegedAction() {
  412.         public Object run() {
  413.         try {
  414.             File propsFile = new File(
  415.               System.getProperty("java.home") + sep + "lib" +
  416.               sep + "accessibility.properties");
  417.             FileInputStream in =
  418.             new FileInputStream(propsFile);
  419.             properties.load(new BufferedInputStream(in));
  420.             in.close();
  421.         } catch (Exception e) {
  422.             // File does not exist; no classes will be auto loaded
  423.         }
  424.         return null;
  425.         }
  426.     });
  427.  
  428.         String atNames = properties.getProperty("assistive_technologies",null);
  429.     ClassLoader cl = ClassLoader.getSystemClassLoader();
  430.  
  431.         if (atNames != null) {
  432.             StringTokenizer parser = new StringTokenizer(atNames,",");
  433.         String atName;
  434.             while (parser.hasMoreTokens()) {
  435.         atName = parser.nextToken();
  436.                 try {
  437.             Class clazz;
  438.             if (cl != null) {
  439.             clazz = cl.loadClass(atName);
  440.             } else {
  441.             clazz = Class.forName(atName);
  442.             }
  443.             clazz.newInstance();
  444.                 } catch (ClassNotFoundException e) {
  445.                     throw new AWTError("Assistive Technology not found: "
  446.                 + atName);
  447.                 } catch (InstantiationException e) {
  448.                     throw new AWTError("Could not instantiate Assistive"
  449.                 + " Technology: " + atName);
  450.                 } catch (IllegalAccessException e) {
  451.                     throw new AWTError("Could not access Assistive"
  452.                 + " Technology: " + atName);
  453.                 } catch (Exception e) {
  454.                     throw new AWTError("Error trying to install Assistive"
  455.                 + " Technology: " + atName + " " + e);
  456.                 }
  457.             }
  458.         }
  459.     }
  460.  
  461.     /**
  462.      * Gets the default toolkit.
  463.      * <p>
  464.      * If there is a system property named <code>"awt.toolkit"</code>,
  465.      * that property is treated as the name of a class that is a subclass
  466.      * of <code>Toolkit</code>.
  467.      * <p>
  468.      * If the system property does not exist, then the default toolkit
  469.      * used is the class named <code>"sun.awt.motif.MToolkit"</code>,
  470.      * which is a motif implementation of the Abstract Window Toolkit.
  471.      * <p>
  472.      * Also loads additional classes into the VM, using the property
  473.      * 'assistive_technologies' specified in the Sun reference
  474.      * implementation by a line in the 'accessibility.properties'
  475.      * file.  The form is "assistive_technologies=..." where
  476.      * the "..." is a comma-separated list of assistive technology
  477.      * classes to load.  Each class is loaded in the order given
  478.      * and a single instance of each is created using
  479.      * Class.forName(class).newInstance().  This is done just after
  480.      * the AWT toolkit is created.  All errors are handled via an
  481.      * AWTError exception.
  482.      * @return    the default toolkit.
  483.      * @exception  AWTError  if a toolkit could not be found, or
  484.      *                 if one could not be accessed or instantiated.
  485.      */
  486.     public static synchronized Toolkit getDefaultToolkit() {
  487.     if (toolkit == null) {
  488.         try {
  489.         // We disable the JIT during toolkit initialization.  This
  490.         // tends to touch lots of classes that aren't needed again
  491.         // later and therefore JITing is counter-productiive.
  492.         java.lang.Compiler.disable();
  493.  
  494.             java.security.AccessController.doPrivileged(
  495.             new java.security.PrivilegedAction() {
  496.             public Object run() {
  497.                 String nm = null;
  498.                 try {
  499.                 nm = System.getProperty("awt.toolkit",
  500.                         "sun.awt.motif.MToolkit");
  501.                 toolkit = (Toolkit)Class.forName(nm).newInstance();
  502.                 } catch (ClassNotFoundException e) {
  503.                 throw new AWTError("Toolkit not found: " + nm);
  504.                 } catch (InstantiationException e) {
  505.                 throw new AWTError("Could not instantiate Toolkit: " +
  506.                        nm);
  507.                 } catch (IllegalAccessException e) {
  508.                 throw new AWTError("Could not access Toolkit: " + nm);
  509.                 }
  510.                 return null;
  511.             }
  512.             });
  513.             loadAssistiveTechnologies();
  514.  
  515.         } finally {
  516.         // Make sure to always re-enable the JIT.
  517.         java.lang.Compiler.enable();
  518.         }
  519.     }
  520.     return toolkit;
  521.     }
  522.  
  523.     /**
  524.      * Returns an image which gets pixel data from the specified file.
  525.      * The underlying toolkit attempts to resolve multiple requests
  526.      * with the same filename to the same returned Image.
  527.      * Since the mechanism required to facilitate this sharing of
  528.      * Image objects may continue to hold onto images that are no
  529.      * longer of use for an indefinate period of time, developers
  530.      * are encouraged to implement their own caching of images by
  531.      * using the createImage variant wherever available.
  532.      * @param     filename   the name of a file containing pixel data
  533.      *                         in a recognized file format.
  534.      * @return    an image which gets its pixel data from
  535.      *                         the specified file.
  536.      * @see createImage(java.lang.String)
  537.      */
  538.     public abstract Image getImage(String filename);
  539.  
  540.     /**
  541.      * Returns an image which gets pixel data from the specified URL.
  542.      * The underlying toolkit attempts to resolve multiple requests
  543.      * with the same URL to the same returned Image.
  544.      * Since the mechanism required to facilitate this sharing of
  545.      * Image objects may continue to hold onto images that are no
  546.      * longer of use for an indefinate period of time, developers
  547.      * are encouraged to implement their own caching of images by
  548.      * using the createImage variant wherever available.
  549.      * @param     url   the URL to use in fetching the pixel data.
  550.      * @return    an image which gets its pixel data from
  551.      *                         the specified URL.
  552.      * @see createImage(java.net.URL)
  553.      */
  554.     public abstract Image getImage(URL url);
  555.  
  556.     /**
  557.      * Returns an image which gets pixel data from the specified file.
  558.      * The returned Image is a new object which will not be shared
  559.      * with any other caller of this method or its getImage variant.
  560.      * @param     filename   the name of a file containing pixel data
  561.      *                         in a recognized file format.
  562.      * @return    an image which gets its pixel data from
  563.      *                         the specified file.
  564.      * @see getImage(java.lang.String)
  565.      */
  566.     public abstract Image createImage(String filename);
  567.  
  568.     /**
  569.      * Returns an image which gets pixel data from the specified URL.
  570.      * The returned Image is a new object which will not be shared
  571.      * with any other caller of this method or its getImage variant.
  572.      * @param     url   the URL to use in fetching the pixel data.
  573.      * @return    an image which gets its pixel data from
  574.      *                         the specified URL.
  575.      * @see getImage(java.net.URL)
  576.      */
  577.     public abstract Image createImage(URL url);
  578.  
  579.     /**
  580.      * Prepares an image for rendering.
  581.      * <p>
  582.      * If the values of the width and height arguments are both
  583.      * <code>-1</code>, this method prepares the image for rendering
  584.      * on the default screen; otherwise, this method prepares an image
  585.      * for rendering on the default screen at the specified width and height.
  586.      * <p>
  587.      * The image data is downloaded asynchronously in another thread,
  588.      * and an appropriately scaled screen representation of the image is
  589.      * generated.
  590.      * <p>
  591.      * This method is called by components <code>prepareImage</code>
  592.      * methods.
  593.      * <p>
  594.      * Information on the flags returned by this method can be found
  595.      * with the definition of the <code>ImageObserver</code> interface.
  596.  
  597.      * @param     image      the image for which to prepare a
  598.      *                           screen representation.
  599.      * @param     width      the width of the desired screen
  600.      *                           representation, or <code>-1</code>.
  601.      * @param     height     the height of the desired screen
  602.      *                           representation, or <code>-1</code>.
  603.      * @param     observer   the <code>ImageObserver</code>
  604.      *                           object to be notified as the
  605.      *                           image is being prepared.
  606.      * @return    <code>true</code> if the image has already been
  607.      *                 fully prepared; <code>false</code> otherwise.
  608.      * @see       java.awt.Component#prepareImage(java.awt.Image,
  609.      *                 java.awt.image.ImageObserver)
  610.      * @see       java.awt.Component#prepareImage(java.awt.Image,
  611.      *                 int, int, java.awt.image.ImageObserver)
  612.      * @see       java.awt.image.ImageObserver
  613.      */
  614.     public abstract boolean prepareImage(Image image, int width, int height,
  615.                      ImageObserver observer);
  616.  
  617.     /**
  618.      * Indicates the construction status of a specified image that is
  619.      * being prepared for display.
  620.      * <p>
  621.      * If the values of the width and height arguments are both
  622.      * <code>-1</code>, this method returns the construction status of
  623.      * a screen representation of the specified image in this toolkit.
  624.      * Otherwise, this method returns the construction status of a
  625.      * scaled representation of the image at the specified width
  626.      * and height.
  627.      * <p>
  628.      * This method does not cause the image to begin loading.
  629.      * An application must call <code>prepareImage</code> to force
  630.      * the loading of an image.
  631.      * <p>
  632.      * This method is called by the component's <code>checkImage</code>
  633.      * methods.
  634.      * <p>
  635.      * Information on the flags returned by this method can be found
  636.      * with the definition of the <code>ImageObserver</code> interface.
  637.      * @param     image   the image whose status is being checked.
  638.      * @param     width   the width of the scaled version whose status is
  639.      *                 being checked, or <code>-1</code>.
  640.      * @param     height  the height of the scaled version whose status
  641.      *                 is being checked, or <code>-1</code>.
  642.      * @param     observer   the <code>ImageObserver</code> object to be
  643.      *                 notified as the image is being prepared.
  644.      * @return    the bitwise inclusive <strong>OR</strong> of the
  645.      *                 <code>ImageObserver</code> flags for the
  646.      *                 image data that is currently available.
  647.      * @see       java.awt.Toolkit#prepareImage(java.awt.Image,
  648.      *                 int, int, java.awt.image.ImageObserver)
  649.      * @see       java.awt.Component#checkImage(java.awt.Image,
  650.      *                 java.awt.image.ImageObserver)
  651.      * @see       java.awt.Component#checkImage(java.awt.Image,
  652.      *                 int, int, java.awt.image.ImageObserver)
  653.      * @see       java.awt.image.ImageObserver
  654.      */
  655.     public abstract int checkImage(Image image, int width, int height,
  656.                    ImageObserver observer);
  657.  
  658.     /**
  659.      * Creates an image with the specified image producer.
  660.      * @param     producer the image producer to be used.
  661.      * @return    an image with the specified image producer.
  662.      * @see       java.awt.Image
  663.      * @see       java.awt.image.ImageProducer
  664.      * @see       java.awt.Component#createImage(java.awt.image.ImageProducer)
  665.      */
  666.     public abstract Image createImage(ImageProducer producer);
  667.  
  668.     /**
  669.      * Creates an image which decodes the image stored in the specified
  670.      * byte array.
  671.      * <p>
  672.      * The data must be in some image format, such as GIF or JPEG,
  673.      * that is supported by this toolkit.
  674.      * @param     imagedata   an array of bytes, representing
  675.      *                         image data in a supported image format.
  676.      * @return    an image.
  677.      * @since     JDK1.1
  678.      */
  679.     public Image createImage(byte[] imagedata) {
  680.     return createImage(imagedata, 0, imagedata.length);
  681.     }
  682.  
  683.     /**
  684.      * Creates an image which decodes the image stored in the specified
  685.      * byte array, and at the specified offset and length.
  686.      * The data must be in some image format, such as GIF or JPEG,
  687.      * that is supported by this toolkit.
  688.      * @param     imagedata   an array of bytes, representing
  689.      *                         image data in a supported image format.
  690.      * @param     imageoffset  the offset of the beginning
  691.      *                         of the data in the array.
  692.      * @param     imagelength  the length of the data in the array.
  693.      * @return    an image.
  694.      * @since     JDK1.1
  695.      */
  696.     public abstract Image createImage(byte[] imagedata,
  697.                       int imageoffset,
  698.                       int imagelength);
  699.  
  700.     /**
  701.      * Gets a <code>PrintJob</code> object which is the result
  702.      * of initiating a print operation on the toolkit's platform.
  703.      * 
  704.      * <p>Each actual implementation of this method should first check if there is a
  705.      * security manager installed. If there is, the method should call the security
  706.      * manager's <code>checkPrintJobAccess</code> method to ensure 
  707.      * initiation of a print operation is allowed.
  708.      * If  the default implementation of <code>checkPrintJobAccess</code> is used
  709.      * (that is, that method is not overriden), then this results in
  710.      * a call to the security manager's <code>checkPermission</code> method
  711.      * with a <code>RuntimePermission("queuePrintJob")</code> permission.
  712.      * 
  713.      * @return    a <code>PrintJob</code> object, or
  714.      *                  <code>null</code> if the user
  715.      *                  cancelled the print job.
  716.      * @see       java.awt.PrintJob
  717.      * @see       java.lang.RuntimePermission
  718.      * @since     JDK1.1
  719.      */
  720.     public abstract PrintJob getPrintJob(Frame frame, String jobtitle, Properties props);
  721.  
  722.     /**
  723.      * Emits an audio beep.
  724.      * @since     JDK1.1
  725.      */
  726.     public abstract void beep();
  727.  
  728.     /**
  729.      * Gets an instance of the system clipboard which interfaces
  730.      * with clipboard facilities provided by the native platform.
  731.      * 
  732.      * <p>This clipboard enables data transfer between Java programs
  733.      * and native applications which use native clipboard facilities.
  734.      * 
  735.      * <p>Each actual implementation of this method should first check if there is a
  736.      * security manager installed. If there is, the method should call the security
  737.      * manager's <code>checkSystemClipboardAccess</code> method to ensure 
  738.      * it's ok to to access the system clipboard.
  739.      * If  the default implementation of <code>checkSystemClipboardAccess</code> 
  740.      * is used (that is, that method is not overriden), then this results in
  741.      * a call to the security manager's <code>checkPermission</code> method
  742.      * with an <code>AWTPermission("accessClipboard")</code> permission.
  743.      * 
  744.      * @return    an instance of the system clipboard.
  745.      * @see       java.awt.datatransfer.Clipboard
  746.      * @see       java.awt.AWTPermission
  747.      * @since     JDK1.1
  748.      */
  749.     public abstract Clipboard getSystemClipboard();
  750.  
  751.     /**
  752.      * Determines which modifier key is the appropriate accelerator
  753.      * key for menu shortcuts.
  754.      * <p>
  755.      * Menu shortcuts, which are embodied in the
  756.      * <code>MenuShortcut</code> class, are handled by the
  757.      * <code>MenuBar</code> class.
  758.      * <p>
  759.      * By default, this method returns <code>Event.CTRL_MASK</code>.
  760.      * Toolkit implementations should override this method if the
  761.      * <b>Control</b> key isn't the correct key for accelerators.
  762.      * @return    the modifier mask on the <code>Event</code> class
  763.      *                 that is used for menu shortcuts on this toolkit.
  764.      * @see       java.awt.MenuBar
  765.      * @see       java.awt.MenuShortcut
  766.      * @since     JDK1.1
  767.      */
  768.     public int getMenuShortcutKeyMask() {
  769.         return Event.CTRL_MASK;
  770.     }
  771.  
  772.     /**
  773.      * Give native peers the ability to query the native container
  774.      * given a native component (eg the direct parent may be lightweight).
  775.      */
  776.     protected static Container getNativeContainer(Component c) {
  777.     return c.getNativeContainer();
  778.     }
  779.  
  780.     /**
  781.      * Creates a new custom cursor object.
  782.      * @param image the image to display when the cursor is active.
  783.      * @param hotSpot the X and Y of the large cursor's hot spot.  The
  784.      * hotSpot values must be less than the Dimension returned by
  785.      * getBestCursorSize().
  786.      * @param     name a localized description of the cursor, for Java Accessibility use.
  787.      * @exception IndexOutOfBoundsException if the hotSpot values are outside
  788.      * the bounds of the cursor.
  789.      * @since     JDK1.2
  790.      */
  791.     public Cursor createCustomCursor(Image cursor, Point hotSpot, String name)
  792.         throws IndexOutOfBoundsException {
  793.         // Override to implement custom cursor support.
  794.         return new Cursor(Cursor.DEFAULT_CURSOR);
  795.     }
  796.  
  797.     /**
  798.      * Returns the supported cursor dimension which is closest to the desired
  799.      * sizes.  Systems which only support a single cursor size will return that
  800.      * size regardless of the desired sizes.  Systems which don't support custom
  801.      * cursors will return a dimension of 0, 0. <p>
  802.      * Note:  if an image is used whose dimensions don't match a supported size
  803.      * (as returned by this method), the Toolkit implementation will attempt to
  804.      * resize the image to a supported size.
  805.      * Since converting low-resolution images is difficult,
  806.      * no guarantees are made as to the quality of a cursor image which isn't a
  807.      * supported size.  It is therefore recommended that this method
  808.      * be called and an appropriate image used so no image conversion is made.
  809.      *
  810.      * @param     desiredWidth the preferred cursor width the component would like
  811.      * to use.
  812.      * @param     desiredHeight the preferred cursor height the component would like
  813.      * to use.
  814.      * @return    the closest matching supported cursor size, or a dimension of 0,0 if
  815.      * the Toolkit implementation doesn't support custom cursors.
  816.      * @since     JDK1.2
  817.      */
  818.     public Dimension getBestCursorSize(int preferredWidth, int preferredHeight) {
  819.         // Override to implement custom cursor support.
  820.         return new Dimension(0, 0);
  821.     }
  822.  
  823.     /**
  824.      * Returns the maximum number of colors the Toolkit supports in a custom cursor
  825.      * palette.<p>
  826.      * Note: if an image is used which has more colors in its palette than
  827.      * the supported maximum, the Toolkit implementation will attempt to flatten the
  828.      * palette to the maximum.  Since converting low-resolution images is difficult,
  829.      * no guarantees are made as to the quality of a cursor image which has more
  830.      * colors than the system supports.  It is therefore recommended that this method
  831.      * be called and an appropriate image used so no image conversion is made.
  832.      *
  833.      * @return    the maximum number of colors, or zero if custom cursors are not
  834.      * supported by this Toolkit implementation.
  835.      * @since     JDK1.2
  836.      */
  837.     public int getMaximumCursorColors() {
  838.         // Override to implement custom cursor support.
  839.         return 0;
  840.     }
  841.  
  842.     /**
  843.      * Support for I18N: any visible strings should be stored in
  844.      * java.awt.resources.awt.properties.  The ResourceBundle is stored
  845.      * here, so that only one copy is maintained.
  846.      */
  847.     private static ResourceBundle resources;
  848.  
  849.     /**
  850.      * Initialize JNI field and method ids
  851.      */
  852.     private static native void initIDs();
  853.  
  854.     /**
  855.      * WARNING: This is a temporary workaround for a problem in the
  856.      * way the AWT loads native libraries. A number of classes in the
  857.      * AWT package have a native method, initIDs(), which initializes
  858.      * the JNI field and method ids used in the native portion of
  859.      * their implementation.
  860.      *
  861.      * Since the use and storage of these ids is done by the
  862.      * implementation libraries, the implementation of these method is
  863.      * provided by the particular AWT implementations
  864.      * (i.e. "Toolkit"s/Peer), such as Motif, Win32 or Tiny. The
  865.      * problem is that this means that the native libraries must be
  866.      * loaded by the java.* classes, which do not necessarily know the
  867.      * names of the libraries to load. A better way of doing this
  868.      * would be to provide a separate library which defines java.awt.*
  869.      * initIDs, and exports the relevant symbols out to the
  870.      * implementation libraries.
  871.      *
  872.      * For now, we know it's done by the implementation, and we assume
  873.      * that the name of the library is "awt".  -br.
  874.      *
  875.      * If you change loadLibraries(), please add the change to
  876.      * java.awt.image.ColorModel.loadLibraries(). Unfortunately,
  877.      * classes can be loaded in java.awt.image that depend on
  878.      * libawt and there is no way to call Toolkit.loadLibraries()
  879.      * directly.  -hung
  880.      */
  881.     private static boolean loaded = false;
  882.     static void loadLibraries() {
  883.     if (!loaded) {
  884.         java.security.AccessController.doPrivileged(
  885.               new sun.security.action.LoadLibraryAction("awt"));
  886.         loaded = true;
  887.         }
  888.     }
  889.  
  890.     static {
  891.     java.security.AccessController.doPrivileged(
  892.                  new java.security.PrivilegedAction() {
  893.         public Object run() {
  894.         try {
  895.             resources =
  896.             ResourceBundle.getBundle("java.awt.resources.awt");
  897.         } catch (MissingResourceException e) {
  898.             // No resource file; defaults will be used.
  899.         }
  900.         return null;
  901.         }
  902.     });
  903.  
  904.     // ensure that the proper libraries are loaded
  905.         loadLibraries();
  906.     initIDs();
  907.     }
  908.  
  909.     /**
  910.      * Gets a property with the specified key and default.
  911.      * This method returns defaultValue if the property is not found.
  912.      */
  913.     public static String getProperty(String key, String defaultValue) {
  914.         if (resources != null) {
  915.         try {
  916.             return resources.getString(key);
  917.         }
  918.         catch (MissingResourceException e) {}
  919.         }
  920.  
  921.     return defaultValue;
  922.     }
  923.  
  924.     /**
  925.      * Get the application's or applet's EventQueue instance.
  926.      * Depending on the Toolkit implementation, different EventQueues
  927.      * may be returned for different applets.  Applets should
  928.      * therefore not assume that the EventQueue instance returned
  929.      * by this method will be shared by other applets or the system.
  930.      * 
  931.      * <p>First, if there is a security manager, its 
  932.      * <code>checkAwtEventQueueAccess</code> 
  933.      * method is called. 
  934.      * If  the default implementation of <code>checkAwtEventQueueAccess</code> 
  935.      * is used (that is, that method is not overriden), then this results in
  936.      * a call to the security manager's <code>checkPermission</code> method
  937.      * with an <code>AWTPermission("accessEventQueue")</code> permission.
  938.      * 
  939.      * @return    the <code>EventQueue</code> object.
  940.      * @throws  SecurityException
  941.      *          if a security manager exists and its <code>{@link
  942.      *          java.lang.SecurityManager#checkAwtEventQueueAccess}</code> method denies
  943.      *          access to the EventQueue.
  944.      * @see       java.awt.AWTPermission
  945.     */
  946.     public final EventQueue getSystemEventQueue() {
  947.         SecurityManager security = System.getSecurityManager();
  948.         if (security != null) {
  949.       security.checkAwtEventQueueAccess();
  950.         }
  951.         return getSystemEventQueueImpl();
  952.     }
  953.  
  954.     /*
  955.      * Get the application's or applet's EventQueue instance, without
  956.      * checking access.  For security reasons, this can only be called
  957.      * from a Toolkit subclass.  Implementations wishing to modify
  958.      * the default EventQueue support should subclass this method.
  959.      */
  960.     protected abstract EventQueue getSystemEventQueueImpl();
  961.  
  962.     /* Accessor method for use by AWT package routines. */
  963.     static EventQueue getEventQueue() {
  964.         return getDefaultToolkit().getSystemEventQueueImpl();
  965.     }
  966.  
  967.     /**
  968.      * create the peer for a DragSourceContext
  969.      */
  970.  
  971.     public abstract DragSourceContextPeer createDragSourceContextPeer(DragGestureEvent dge) throws InvalidDnDOperationException;
  972.  
  973.     /**
  974.      * create a concrete, platform dependent, subclass of the abstract
  975.      * DragGestureRecognizer class requested, and associate it with the
  976.      * DragSource, Component and DragGestureListener specified
  977.      *
  978.      * subclasses should override this to provide their own implementation
  979.      *
  980.      * @param abstractRecognizerClass The abstract class of the required recognizer
  981.      * @param ds              The DragSource
  982.      * @param c                  The Component target for the DragGestureRecognizer
  983.      * @param srcActions          The actions permitted for the gesture
  984.      * @param dgl              The DragGestureListener
  985.      *
  986.      * @Return the new object or null
  987.      */
  988.  
  989.     public DragGestureRecognizer createDragGestureRecognizer(Class abstractRecognizerClass, DragSource ds, Component c, int srcActions, DragGestureListener dgl) {
  990.     return null;
  991.     }
  992.  
  993.     /**
  994.      * obtain a value for the specified desktop property.
  995.      *
  996.      * A desktop property is a uniquely named value for a resource that
  997.      * is Toolkit global in nature. Usually it also is an abstract representation
  998.      * for an underlying platform dependent desktop setting.
  999.      */
  1000.  
  1001.     public final synchronized Object getDesktopProperty(String propertyName) {
  1002.  
  1003.     if (desktopProperties.isEmpty()) {
  1004.         initializeDesktopProperties();
  1005.     }
  1006.  
  1007.     Object value = desktopProperties.get(propertyName);
  1008.  
  1009.     if (value == null) {
  1010.         value = lazilyLoadDesktopProperty(propertyName);
  1011.  
  1012.         if (value != null) {
  1013.         setDesktopProperty(propertyName, value);
  1014.         }
  1015.     }
  1016.  
  1017.     return value;
  1018.     }
  1019.  
  1020.     /**
  1021.      * set the named desktop property to the specified value and fire a
  1022.      * property change event to notify any listeners that the value has changed
  1023.      */
  1024.  
  1025.     protected final synchronized void setDesktopProperty(String name, Object newValue) {
  1026.     Object oldValue = desktopProperties.get(name);
  1027.  
  1028.     desktopProperties.put(name, newValue);
  1029.  
  1030.     desktopPropsSupport.firePropertyChange(name, oldValue, newValue);
  1031.     }
  1032.  
  1033.     /**
  1034.      * an opportunity to lazily evaluate desktop property values.
  1035.      */
  1036.  
  1037.     protected Object lazilyLoadDesktopProperty(String name) {
  1038.     return null;
  1039.     }
  1040.  
  1041.     /**
  1042.      * initializeDesktopProperties
  1043.      */
  1044.  
  1045.     protected void initializeDesktopProperties() {
  1046.     }
  1047.  
  1048.     /**
  1049.      * add the specified property change listener for the named desktop 
  1050.      * property
  1051.      * If pcl is null, no exception is thrown and no action is performed.
  1052.      *
  1053.      * @param     name The name of the property to listen for
  1054.      * @param    pcl The property change listener
  1055.      */
  1056.     public synchronized void addPropertyChangeListener(String name, PropertyChangeListener pcl) {
  1057.     if (pcl == null) {
  1058.         return;
  1059.     }
  1060.     desktopPropsSupport.addPropertyChangeListener(name, pcl);
  1061.     }
  1062.  
  1063.     /**
  1064.      * remove the specified property change listener for the named 
  1065.      * desktop property
  1066.      * If pcl is null, no exception is thrown and no action is performed.
  1067.      *
  1068.      */
  1069.     public synchronized void removePropertyChangeListener(String name, PropertyChangeListener pcl) {
  1070.     if (pcl == null) {
  1071.         return;
  1072.     }
  1073.     desktopPropsSupport.removePropertyChangeListener(name, pcl);
  1074.     }
  1075.  
  1076.     protected final Map                  desktopProperties   = new HashMap();
  1077.     protected final PropertyChangeSupport desktopPropsSupport = new PropertyChangeSupport(this);
  1078.  
  1079.     private AWTEventListener eventListener = null;
  1080.     private WeakHashMap listener2SelectiveListener = new WeakHashMap();
  1081.  
  1082.     private AWTPermission listenToAllAWTEventsPermission = null;
  1083.  
  1084.     /**
  1085.      * Adds an AWTEventListener to receive all AWTEvents dispatched
  1086.      * system-wide that conform to the given <code>eventMask</code>.
  1087.      * <p>
  1088.      * First, if there is a security manager, its <code>checkPermission</code> 
  1089.      * method is called with an 
  1090.      * <code>AWTPermission("listenToAllAWTEvents")</code> permission.
  1091.      * This may result in a SecurityException. 
  1092.      * <p>
  1093.      * <code>eventMask</code> is a bitmask of event types to receive.
  1094.      * It is constructed by bitwise OR-ing together the event masks
  1095.      * defined in <code>AWTEvent</code>.
  1096.      * <p>
  1097.      * Note:  event listener use is not recommended for normal
  1098.      * application use, but are intended solely to support special
  1099.      * purpose facilities including support for accessibility,
  1100.      * event record/playback, and diagnostic tracing.
  1101.      *
  1102.      * If listener is null, no exception is thrown and no action is performed.
  1103.      *
  1104.      * @param    listener   the event listener.
  1105.      * @param    eventMask  the bitmask of event types to receive
  1106.      * @throws SecurityException
  1107.      *        if a security manager exists and its 
  1108.      *        <code>checkPermission</code> method doesn't allow the operation.
  1109.      * @see      java.awt.event.AWTEventListener
  1110.      * @see      java.awt.Toolkit#addEventListener
  1111.      * @see      java.awt.AWTEvent
  1112.      * @see      SecurityManager#checkPermission
  1113.      * @see      java.awt.AWTPermission
  1114.      * @since    JDK1.2
  1115.      */
  1116.     public void addAWTEventListener(AWTEventListener listener, long eventMask) {
  1117.     if (listener == null) {
  1118.         return;
  1119.     }
  1120.         SecurityManager security = System.getSecurityManager();
  1121.         if (security != null) {
  1122.       if (listenToAllAWTEventsPermission == null) {
  1123.         listenToAllAWTEventsPermission =
  1124.             new AWTPermission("listenToAllAWTEvents");
  1125.       }
  1126.       security.checkPermission(listenToAllAWTEventsPermission);
  1127.         }
  1128.     synchronized (this) {
  1129.         SelectiveAWTEventListener selectiveListener =
  1130.         new SelectiveAWTEventListener(listener, eventMask);
  1131.         listener2SelectiveListener.put(listener, selectiveListener);
  1132.         eventListener = ToolkitEventMulticaster.add(eventListener,
  1133.                             selectiveListener);
  1134.     }
  1135.     }
  1136.  
  1137.     /**
  1138.      * Removes an AWTEventListener from receiving dispatched AWTEvents.
  1139.      * <p>
  1140.      * First, if there is a security manager, its <code>checkPermission</code> 
  1141.      * method is called with an 
  1142.      * <code>AWTPermission("listenToAllAWTEvents")</code> permission.
  1143.      * This may result in a SecurityException. 
  1144.      * <p>
  1145.      * Note:  event listener use is not recommended for normal
  1146.      * application use, but are intended solely to support special
  1147.      * purpose facilities including support for accessibility,
  1148.      * event record/playback, and diagnostic tracing.
  1149.      *
  1150.      * If listener is null, no exception is thrown and no action is performed.
  1151.      *
  1152.      * @param    listener   the event listener.
  1153.      * @throws SecurityException
  1154.      *        if a security manager exists and its 
  1155.      *        <code>checkPermission</code> method doesn't allow the operation.
  1156.      * @see      java.awt.event.AWTEventListener
  1157.      * @see      java.awt.Toolkit#addEventListener
  1158.      * @see      java.awt.AWTEvent
  1159.      * @see      SecurityManager#checkPermission
  1160.      * @see      java.awt.AWTPermission
  1161.      * @since    JDK1.2
  1162.      */
  1163.     public void removeAWTEventListener(AWTEventListener listener) {
  1164.     if (listener == null) {
  1165.         return;
  1166.     }
  1167.         SecurityManager security = System.getSecurityManager();
  1168.         if (security != null) {
  1169.       if (listenToAllAWTEventsPermission == null) {
  1170.         listenToAllAWTEventsPermission =
  1171.             new AWTPermission("listenToAllAWTEvents");
  1172.       }
  1173.       security.checkPermission(listenToAllAWTEventsPermission);
  1174.         }
  1175.     synchronized (this) {
  1176.         SelectiveAWTEventListener selectiveListener =
  1177.         (SelectiveAWTEventListener)listener2SelectiveListener
  1178.         .get(listener);
  1179.         if (selectiveListener != null)
  1180.         listener2SelectiveListener.remove(listener);
  1181.         eventListener = ToolkitEventMulticaster.remove(eventListener,
  1182.         (selectiveListener == null) ? listener : selectiveListener);
  1183.     }
  1184.     }
  1185.  
  1186.     /*
  1187.      * This method notifies any AWTEventListeners that an event
  1188.      * is about to be dispatched.
  1189.      *
  1190.      * @param theEvent the event which will be dispatched.
  1191.      */
  1192.     void notifyAWTEventListeners(AWTEvent theEvent) {
  1193.         if (eventListener != null) {
  1194.         synchronized (this) {
  1195.         if (eventListener != null)
  1196.             eventListener.eventDispatched(theEvent);
  1197.         }
  1198.         }
  1199.     }
  1200.  
  1201.     static private class ToolkitEventMulticaster extends AWTEventMulticaster
  1202.         implements AWTEventListener {
  1203.         // Implementation cloned from AWTEventMulticaster.
  1204.  
  1205.         ToolkitEventMulticaster(AWTEventListener a, AWTEventListener b) {
  1206.             super(a, b);
  1207.         }
  1208.  
  1209.         static AWTEventListener add(AWTEventListener a, 
  1210.                                     AWTEventListener b) {
  1211.         if (a == null)  return b;
  1212.         if (b == null)  return a;
  1213.         return new ToolkitEventMulticaster(a, b);
  1214.         }
  1215.  
  1216.         static AWTEventListener remove(AWTEventListener l, 
  1217.                                        AWTEventListener oldl) {
  1218.             return (AWTEventListener) removeInternal(l, oldl);
  1219.         }
  1220.  
  1221.  
  1222.     // #4178589: must overload remove(EventListener) to call our add()
  1223.  
  1224.     // instead of the static addInternal() so we allocate a
  1225.  
  1226.     // ToolkitEventMulticaster instead of an AWTEventMulticaster.
  1227.  
  1228.     // Note: this method is called by AWTEventListener.removeInternal(),
  1229.  
  1230.     // so its method signature must match AWTEventListener.remove().
  1231.  
  1232.     protected EventListener remove(EventListener oldl) {
  1233.  
  1234.         if (oldl == a)  return b;
  1235.  
  1236.         if (oldl == b)  return a;
  1237.  
  1238.         AWTEventListener a2 = (AWTEventListener)removeInternal(a, oldl);
  1239.  
  1240.         AWTEventListener b2 = (AWTEventListener)removeInternal(b, oldl);
  1241.  
  1242.         if (a2 == a && b2 == b) {
  1243.  
  1244.         return this;    // it's not here
  1245.  
  1246.         }
  1247.  
  1248.         return add(a2, b2);
  1249.  
  1250.     }
  1251.  
  1252.  
  1253.  
  1254.         public void eventDispatched(AWTEvent event) {
  1255.             ((AWTEventListener)a).eventDispatched(event);
  1256.             ((AWTEventListener)b).eventDispatched(event);
  1257.         }
  1258.     }
  1259.  
  1260.     private class SelectiveAWTEventListener implements AWTEventListener {
  1261.     AWTEventListener listener;
  1262.     private long eventMask;
  1263.  
  1264.     SelectiveAWTEventListener(AWTEventListener l, long mask) {
  1265.         listener = l;
  1266.         eventMask = mask;
  1267.     }
  1268.  
  1269.         public void eventDispatched(AWTEvent event) {
  1270.         if (((eventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0 &&
  1271.          event.id >= ComponentEvent.COMPONENT_FIRST &&
  1272.          event.id <= ComponentEvent.COMPONENT_LAST)
  1273.          || ((eventMask & AWTEvent.CONTAINER_EVENT_MASK) != 0 &&
  1274.          event.id >= ContainerEvent.CONTAINER_FIRST &&
  1275.          event.id <= ContainerEvent.CONTAINER_LAST)
  1276.          || ((eventMask & AWTEvent.FOCUS_EVENT_MASK) != 0 &&
  1277.          event.id >= FocusEvent.FOCUS_FIRST &&
  1278.          event.id <= FocusEvent.FOCUS_LAST)
  1279.          || ((eventMask & AWTEvent.KEY_EVENT_MASK) != 0 &&
  1280.          event.id >= KeyEvent.KEY_FIRST &&
  1281.          event.id <= KeyEvent.KEY_LAST)
  1282.          || ((eventMask & AWTEvent.MOUSE_MOTION_EVENT_MASK) != 0 &&
  1283.              (event.id == MouseEvent.MOUSE_MOVED ||
  1284.               event.id == MouseEvent.MOUSE_DRAGGED))
  1285.          || ((eventMask & AWTEvent.MOUSE_EVENT_MASK) != 0 &&
  1286.              event.id != MouseEvent.MOUSE_MOVED &&
  1287.              event.id != MouseEvent.MOUSE_DRAGGED &&
  1288.          event.id >= MouseEvent.MOUSE_FIRST &&
  1289.          event.id <= MouseEvent.MOUSE_LAST)
  1290.          || ((eventMask & AWTEvent.WINDOW_EVENT_MASK) != 0 &&
  1291.          event.id >= WindowEvent.WINDOW_FIRST &&
  1292.          event.id <= WindowEvent.WINDOW_LAST)
  1293.          || ((eventMask & AWTEvent.ACTION_EVENT_MASK) != 0 &&
  1294.          event.id >= ActionEvent.ACTION_FIRST &&
  1295.          event.id <= ActionEvent.ACTION_LAST)
  1296.          || ((eventMask & AWTEvent.ADJUSTMENT_EVENT_MASK) != 0 &&
  1297.          event.id >= AdjustmentEvent.ADJUSTMENT_FIRST &&
  1298.          event.id <= AdjustmentEvent.ADJUSTMENT_LAST)
  1299.          || ((eventMask & AWTEvent.ITEM_EVENT_MASK) != 0 &&
  1300.          event.id >= ItemEvent.ITEM_FIRST &&
  1301.          event.id <= ItemEvent.ITEM_LAST)
  1302.          || ((eventMask & AWTEvent.TEXT_EVENT_MASK) != 0 &&
  1303.          event.id >= TextEvent.TEXT_FIRST &&
  1304.          event.id <= TextEvent.TEXT_LAST)
  1305.          || ((eventMask & AWTEvent.INPUT_METHOD_EVENT_MASK) != 0 &&
  1306.          event.id >= InputMethodEvent.INPUT_METHOD_FIRST &&
  1307.          event.id <= InputMethodEvent.INPUT_METHOD_LAST)) {
  1308.         listener.eventDispatched(event);
  1309.         }
  1310.         }
  1311.     }
  1312. }
  1313.  
  1314.  
  1315.  
  1316. /**
  1317.  * Implements the LightweightPeer interface for use in lightweight components
  1318.  * that have no native window associated with them.  This gets created by
  1319.  * default in Component so that Component and Container can be directly
  1320.  * extended to create useful components written entirely in java.  These
  1321.  * components must be hosted somewhere higher up in the component tree by a
  1322.  * native container (such as a Frame).
  1323.  *
  1324.  * This implementation provides no useful semantics and serves only as a
  1325.  * marker.  One could provide alternative implementations in java that do
  1326.  * something useful for some of the other peer interfaces to minimize the
  1327.  * native code.
  1328.  *
  1329.  * @author Timothy Prinzing
  1330.  */
  1331. class LightweightPeer implements java.awt.peer.LightweightPeer {
  1332.  
  1333.     public LightweightPeer(Component target) {
  1334.     }
  1335.  
  1336.     public boolean isFocusTraversable() {
  1337.     return false;
  1338.     }
  1339.  
  1340.     public void setVisible(boolean b) {
  1341.     }
  1342.  
  1343.     public void show() {
  1344.     }
  1345.  
  1346.     public void hide() {
  1347.     }
  1348.  
  1349.     public void setEnabled(boolean b) {
  1350.     }
  1351.  
  1352.     public void enable() {
  1353.     }
  1354.  
  1355.     public void disable() {
  1356.     }
  1357.  
  1358.     public void paint(Graphics g) {
  1359.     }
  1360.  
  1361.     public void repaint(long tm, int x, int y, int width, int height) {
  1362.     }
  1363.  
  1364.     public void print(Graphics g) {
  1365.     }
  1366.  
  1367.     public void setBounds(int x, int y, int width, int height) {
  1368.     }
  1369.  
  1370.     public void reshape(int x, int y, int width, int height) {
  1371.     }
  1372.  
  1373.     public boolean handleEvent(Event e) {
  1374.     return false;
  1375.     }
  1376.  
  1377.     public void handleEvent(java.awt.AWTEvent arg0) {
  1378.     }
  1379.  
  1380.     public Dimension getPreferredSize() {
  1381.     return new Dimension(1,1);
  1382.     }
  1383.  
  1384.     public Dimension getMinimumSize() {
  1385.     return new Dimension(1,1);
  1386.     }
  1387.  
  1388.     public java.awt.Toolkit getToolkit() {
  1389.     return null;
  1390.     }
  1391.  
  1392.     public ColorModel getColorModel() {
  1393.     return null;
  1394.     }
  1395.  
  1396.     public Graphics getGraphics() {
  1397.     return null;
  1398.     }
  1399.  
  1400.     public FontMetrics    getFontMetrics(Font font) {
  1401.     return null;
  1402.     }
  1403.  
  1404.     public void dispose() {
  1405.     // no native code
  1406.     }
  1407.  
  1408.     public void setForeground(Color c) {
  1409.     }
  1410.  
  1411.     public void setBackground(Color c) {
  1412.     }
  1413.  
  1414.     public void setFont(Font f) {
  1415.     }
  1416.  
  1417.     public void setCursor(Cursor cursor) {
  1418.     }
  1419.  
  1420.     public void requestFocus() {
  1421.     }
  1422.  
  1423.     public Image createImage(ImageProducer producer) {
  1424.     return null;
  1425.     }
  1426.  
  1427.     public Image createImage(int width, int height) {
  1428.     return null;
  1429.     }
  1430.  
  1431.     public boolean prepareImage(Image img, int w, int h, ImageObserver o) {
  1432.     return false;
  1433.     }
  1434.  
  1435.     public int    checkImage(Image img, int w, int h, ImageObserver o) {
  1436.     return 0;
  1437.     }
  1438.  
  1439.     public Dimension preferredSize() {
  1440.     return getPreferredSize();
  1441.     }
  1442.  
  1443.     public Dimension minimumSize() {
  1444.     return getMinimumSize();
  1445.     }
  1446.  
  1447.     public Point getLocationOnScreen() {
  1448.     return null;
  1449.     }
  1450.  
  1451. }
  1452.